<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Async&await</title>
</head>
<body>
    <!-- <script src="./03_PromiseClass.js"></script> -->
    <script>
        async function fun1(){
            return 1;
        }
        const result = fun1();
        result.then(value=>{
            console.log(value);
        },
        reason=>{
            console.log(reason)
        })
        console.log(result);

        function fun2(){
            return new Promise((resolve, reject)=>{
                setTimeout(()=>{
                    if(Date.now() %2 === 0){
                        resolve(1)
                    } else {
                        reject(5);
                    }
                }, 2000);
            });
        }

        async function fun3(){
            try {
                const value = await fun2();
                console.log(value)                
            } catch (error) {
                console.warn(error)
            }
        }

        fun3();


    </script>

</body>
</html>